/**
 * @author Hamid Ebadi
 *
 */
public class Calculator {
	// operators 
	private enum CalcOperator {
		PLUS, MINUS , MULTIPLY , DIVISION , EQUAL,  UNDEFINED;
	}
	// Calculate State 
	private CalcOperator CSoperator ;
	private Integer CSoperand  ;
	String CSbuffer  ;
	
	// Methods
	// Constructor 
	Calculator (){
		pressReset();
	}

	public void pressReset(){
		CSbuffer = "" ;
		CSoperand = 0 ;
		CSoperator= CalcOperator.UNDEFINED ;
	}
	public void pressDigit(char digit){
		CSbuffer  = CSbuffer + digit ;
	}
	public void pressPlus(){
		pressOp(CalcOperator.PLUS);
	}
	public void pressMinus(){
		pressOp(CalcOperator.MINUS);
	}
	public void pressMult(){
		pressOp(CalcOperator.MULTIPLY);
	}
	public void pressDiv(){
		pressOp(CalcOperator.DIVISION);
	}
	public void pressEqual(){
		pressOp(CalcOperator.EQUAL);
	}
	public String getBuffer(){
		return CSbuffer ;
	}
	public int getOperand() {
		return CSoperand ;
	}
	private void setOperand(Integer value){
		CSoperand = value ;
	}
	private void pressOp(CalcOperator op) {
		if (CSoperator == CalcOperator.PLUS) setOperand(  getOperand() + Integer.valueOf(CSbuffer));
		if (CSoperator == CalcOperator.MINUS) setOperand( getOperand() - Integer.valueOf(CSbuffer));
		if (CSoperator == CalcOperator.DIVISION) setOperand(  getOperand() / Integer.valueOf(CSbuffer));
		if (CSoperator == CalcOperator.MULTIPLY) setOperand( getOperand() * Integer.valueOf(CSbuffer));
		if (CSoperator == CalcOperator.EQUAL) setOperand(  Integer.valueOf(CSbuffer));
		if (CSoperator == CalcOperator.UNDEFINED) setOperand( Integer.valueOf(CSbuffer));
		CSoperator  = op ;
		CSbuffer = "" ;
	}
	public static void main(String[] args) {
		Calculator calc= new Calculator();
		if (args.length < 1) System.out.println("Missing command-line arguments. ( e.g. 1+3 -4= )\n " );
		for (int i = 0 ; i!= args.length ; i++) {
			for (int j = 0 ; j!= args[i].length() ; j++) {
				char ch = args[i].charAt(j) ;
				if (Character.isDigit(ch)){
					calc.pressDigit(ch);
				}
				switch(ch){
				case '+' :
					calc.pressPlus();
					break;
				case '-' :
					calc.pressMinus();
					break;
				case '/':
					calc.pressDiv();
					break;
				case '*':
					calc.pressMult();
					break;
				case '=':
					calc.pressEqual();
					break;					
				default :
					
				}
				System.out.println("Result of proccessing \"" + ch + "\" :  Operand(Memory) :" + calc.getOperand()+ ",   Digit buffer :" + calc.getBuffer());
			}
		}

	}

}